<?php
// 初始化变量及引入初始文件
$dbPathPart		= '';
$webPathPart	= '';
$jsPathPart		= '';

require('ucCheck.php');

$userSysArr = Cache::PhpFile('userSys');

if ($userSysArr['US_isUserSys'] == 0){
	die('<br /><br /><center>会员系统已关闭，有问题请联系管理员</center>');
}

$username = Users::Username();

if ($username == ''){
	$backURL = urlencode(GetUrl::Query());
	die('
	<br /><br />
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
	<center style="font-size:14px;">
		请先登录，该功能需要登录才能使用。<br />
		如有账号请先 <a style="color:red;" href="./?m=login&force=1&backURL='. $backURL .'">[登录]</a>，如没账号请先 <a style="color:red;" href="./?m=reg&force=1&backURL='. $backURL .'">[注册]</a>
	</center>
	<br /><br />
	');
}

$addiFieldStr = '';
switch ($mudi){
	case 'recom':	$addiFieldStr = ',UE_recomLevel,UE_recomUser,UE_recomNum1,UE_recomNum2,UE_recomNum11,UE_recomNum12';	break;
}
$userRow = Users::Open('get',',UE_username,UE_authStr,UE_groupID,UE_state,UE_cardState,UE_pageNum,UE_pageWapNum'. $addiFieldStr,'',$judUserErr);
	if ((! $userRow) || $judUserErr != ''){
		$backURL = urlencode(GetUrl::Query());
		die('
		<br /><br />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
		<center style="font-size:14px;">
			请先登录，该功能需要登录才能使用（'. $judUserErr .'）。<br />
			如有账号请先 <a style="color:red;" href="./?m=login&force=1&backURL='. $backURL .'">[登录]</a>，如没账号请先 <a style="color:red;" href="./?m=reg&force=1&backURL='. $backURL .'">[注册]</a>
		</center>
		<br /><br />
		');
	}

	if (! in_array($mudi, array('revInfo', 'siteMessage', 'siteMessageAdd', 'siteMessageReply', 'userAndGroup', 'gift', 'workUsers', 'payRecord', 'diyPayRecord', 'moneyRecord', 'userScore','workOrderAdd','workOrderReply','workOrderManage'))){
		// 检测用户邮箱、手机号是否需要强制验证
		AreaApp::UserTixing($userRow['UE_authStr'], $userSysArr, 1);
	}
	if ($userRow['UE_pageNum'] < 1){ $userRow['UE_pageNum'] = 20; }

// 如果手机端访问，手机版有开启，判断手机版独立域名有开启使用，当前网址不是独立域名进行跳转
if ( UcBase::JudMobile() ){
	$wapArr = Cache::PhpFile('wap');
	$currUrl = GetUrl::Query();
	$currDir = GetUrl::Dir();
	if ($wapArr['WAP_domainMode'] == 1 && strlen($wapArr['WAP_domainUrl']) > 7 && strpos($currUrl,$wapArr['WAP_domainUrl']) === false){
		$currUrl = str_replace(array($currDir, 'index.php'), array($wapArr['WAP_domainUrl'] .'users/', ''), $currUrl);
		header('Location: '. $currUrl);
		exit();
	}
}

require(OT_ROOT .'inc/classTemplate.php');

$tpl = new Template;
$tpl->obj->template_dir	= OT_ucROOT .'template/default/';	// 模板目录

// 初始化公共变量
$tpl->webTypeName	= 'usersCenter';
$tpl->webTitle		= '';
$tpl->webKey		= '*';
$tpl->webDesc		= '*';

if (empty($userSysArr['US_userAndGroupName'])){ $userSysArr['US_userAndGroupName'] = '会员和会员组'; }

$webContImg = '';
$menu1 = 'def';	// 默认展开的主菜单
$menu2 = '';	// 默认打开选中的菜单
$webContent = StrInfo::AlertStr('ucAudit0');
switch ($mudi){
	case 'revInfo':
		$menu1		= 'self';
		$webTitle	= '资料密码修改';
		if (Area::UcAudit('|noRightRevInfo|')){
			$webContent = UcMain::RevInfo($userRow['UE_ID']);
		}
		$webContImg = 'address-card-o';
		break;

	case 'userAndGroup':
		$webTitle	= $userSysArr['US_userAndGroupName'];
		$webContent = UcMain::UserAndGroup($userRow['UE_ID']);
		$webContImg = 'address-card-o';
		break;

	case 'userGroupRightList':
		$menu2		= 'userAndGroup';
		$webTitle	= '会员组权限列表';
		$webContent = UserGroup::RightList($userRow['UE_ID']);
		$webContImg = 'address-card-o';
		break;

	case 'log':
		$menu1		= 'self';
		$webTitle	= '会员日志';
		if (Area::UcAudit('|noRightLog|')){
			$webContent = UcMain::LogWeb($userRow['UE_ID']);
		}
		break;

	case 'infoType':
		$webTitle	= $userSysArr['US_infoTypeName'];
		if (Area::UcAudit('|noRightInfoType|')){
			$webContent = UcMain::InfoTypeWeb($userRow['UE_ID']);
		}
		break;

	case 'infoDet':
		$menu2		= 'infoType';
		$webTitle	= '文章详情';
		if (Area::UcAudit('|noRightInfoType|')){
			$webContent = UcMain::InfoDetWeb($userRow['UE_ID']);
		}
		break;

	case 'addNews':
		$webTitle	= '发表文章';
		if (Area::UcAudit()){
			$webContent = UcNews::AddOrRev();
		}
		$webContImg = 'newspaper-o';
		break;

	case 'revNews':
		$menu2		= 'newsManage';
		$webTitle	= '修改文章';
		if (Area::UcAudit()){
			$webContent = UcNews::AddOrRev();
		}
		$webContImg = 'newspaper-o';
		break;

	case 'newsManage':
		$webTitle	= '文章管理';
		$webContent = UcNews::Manage();
		break;

	case 'loginApi':
		$menu1		= 'self';
		$webTitle	= '快捷登录绑定';
		$webContent = AppLogin::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'quan':
		$menu1		= 'money';
		$webTitle	= '卡密充值';
		if (Area::UcAudit('|noRightQuan|')){
			$webContent = AppQuan::UcPayWeb($userRow['UE_ID'],'uc');
		}
		break;

	case 'onlinePay':
		$menu1		= 'money';
		$webTitle	= '在线充值';
		if (Area::UcAudit('|noRightPay|')){
			$webContent = AppMoneyPay::UcPayWeb($userRow['UE_ID'],$userRow['UE_username'],'uc');
		}
		break;

	case 'payRecord':
		$menu1		= 'money';
		$webTitle	= '充值记录';
		$webContent = AppMoneyPay::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'diyPayRecord':
		$menu1		= 'money';
		$webTitle	= '手动充值记录';
		$webContent = AppDiyPay::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'moneyRecord':
		$menu1		= 'money';
		$webTitle	= '财务明细';
		$webContent = AppMoneyRecord::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'userScore':
		$menu1		= 'money';
		$webTitle	= '积分明细';
		$webContent = AppUserScore::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'gift':
		$menu1		= 'func';
		$webTitle	= '积分兑换记录';
		$webContent = AppGift::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'recom':
		$menu1		= 'recom';
		$webTitle	= '邀请好友';
		if (Area::UcAudit()){
			$webContent = AppRecom::UcManage($userRow['UE_ID'],'uc');
		}
		break;

	case 'buyOrders':
		$menu1		= 'func';
		$webTitle	= '订单记录';
		if (Area::UcAudit()){
			$webContent = AppBuyOrders::UcManage($userRow['UE_ID'],'uc');
		}
		break;

	case 'goodsOrder':
		$menu1		= 'func';
		$webTitle	= '淘宝商品认领';
		$webContent = AppTaokeOrder::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'workCenter':
		$menu1		= 'func';
		$webTitle	= '任务中心';
		if (Area::UcAudit('|noRightWorkCenter|')){
			$webContent = AppWorkCenter::UcManage($userRow['UE_ID'],'uc');
		}
		break;

	case 'workUsers':
		$menu1		= 'func';
		$webTitle	= '任务记录';
		$webContent = AppWorkCenter::UcUsers($userRow['UE_ID'],'uc');
		break;

	case 'gainMoney':
		$menu1		= 'recom';
		$webTitle	= '提现记录';
		if (Area::UcAudit()){
			$webContent = AppGain::UcMoneyManage($userRow['UE_ID'],'uc');
		}
		break;

	case 'gainItem':
		$menu1		= 'recom';
		$webTitle	= '佣金记录';
		$webContent = AppGain::UcItemManage($userRow['UE_ID'],'uc');
		break;

	case 'userView':
		$webTitle	= '文章浏览记录';
		$webContent = AppUserView::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'userMark':
		$webTitle	= '文章收藏记录';
		$webContent = AppUserMark::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'infoDown':
		$webTitle	= '文章下载记录';
		$webContent = AppInfoDown::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'siteMessage':
		$webTitle	= '站内信息';
		$webContent = AppSiteMessage::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'siteMessageAdd':
		$menu2		= 'siteMessage';
		$webTitle	= '提交站内信息';
		$webContent = AppSiteMessage::UcAdd($userRow['UE_ID'], '', 'uc');
		break;

	case 'siteMessageReply':
		$menu2		= 'siteMessage';
		$webTitle	= '回复站内信息';
		$webContent = AppSiteMessage::UcReply($userRow['UE_ID'], '', 'uc');
		break;

	case 'api':
		$menu1		= 'self';
		$webTitle	= 'API授权码';
		if (Area::UcAudit('|noRightApi|')){
			$webContent = AppSiteApi::Manage($userRow['UE_ID'],'uc');
		}
		break;

	case 'authSoft':
		$menu1		= 'func';
		$webTitle	= '授权软件管理';
		$webContent = AppAuthSoft::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'ca':
		$menu1		= 'func';
		$webTitle	= '广告管理';
		$webContent = AppCa::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'form':
		$menu1		= 'func';
		$webTitle	= '表单管理';
		$webContent = AppForm::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'formDet':
		$menu1		= 'func';
		$menu2		= 'form';
		$webTitle	= '表单详情列表';
		$webContent = AppForm::UcManageDet($userRow['UE_ID'],'uc');
		break;

	case 'onePage':
		$menu1		= 'func';
		$webTitle	= '功能单页';
		$webContent = AppOnePage::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'onePageRev':
		$menu1		= 'func';
		$menu2		= 'onePage';
		$webTitle	= '修改功能单页';
		$webContent = AppOnePage::UcRev($userRow['UE_ID'],'uc');
		break;

	case 'getGift':
		$menu1		= 'func';
		$webTitle	= '抽奖记录';
		$webContent = AppGetGift::UcManage($userRow['UE_ID'],'uc');
		break;

	case 'adGift':
		$menu1		= 'func';
		$webTitle	= '广告奖励充值';
		if (Area::UcAudit('|noRightAd|')){
			$webContent = AppXcxAd::UcPayWeb($userRow['UE_ID'],'uc');
		}
		break;

	case 'index':
	default :
		$mudi = '';
		$webTitle	= '会员中心';
		$webContent = UcMain::index($userRow['UE_ID']);
		break;

}

if (strlen($mudi) == 0){
	$tpl->webTitle = $webTitle .'_'. $systemArr['SYS_title'];
}else{
	$tpl->webTitle = $webTitle .'_会员中心_'. $systemArr['SYS_title'];
}

if (strlen($menu2) == 0){ $menu2 = $mudi; }
	
if (strlen($webContImg) == 0){ $webContImg = 'snowflake-o'; }
$webContent = MainArea($webContent, $webTitle, $webContImg);


// 财务菜单
$moneyPayMenu = $dropMenuList = '';
if (AppMoneyPay::Jud()){
	if (empty($moneySysArr)){ $moneySysArr = Cache::PhpFile('moneySys'); }
	if ($moneySysArr['MS_isUserPay'] == 1){
		$moneyPayMenu .= SubMenu('onlinePay', '在线充值');
		$dropMenuList .= '<li><a href="usersCenter.php?m=onlinePay"><i class="otcms-uc-215"></i> 在线充值</a></li>';
	}
	$moneyPayMenu .= SubMenu('payRecord', '充值记录');
	$dropMenuList .= '<li><a href="usersCenter.php?m=payRecord"><i class="otcms-uc--13"></i> 充值记录</a></li>';
}

$webTop = '
	<div class="topbar-left">
		<div class="uc-aside-toggler">
			<span class="uc-toggler-bar"></span>
			<span class="uc-toggler-bar"></span>
			<span class="uc-toggler-bar"></span>
		</div>
		<span class="navbar-page-title"> '. $webTitle .'</span>
	</div>
	<ul class="topbar-right">
		<li class="dropdown dropdown-profile">
			<a href="javascript:void(0)" data-toggle="dropdown">
				<img class="img-qrcode img-qrcode-46" src="static/images/def-face.png" alt="用户头像" />
				<span>'. $userRow['UE_username'] .'<span class="caret"></span></span>
			</a>
			<ul class="dropdown-menu dropdown-menu-right" style="top:60px;">
				<li> <a href="?m=revInfo"><i class="otcms-uc-58"></i> 个人信息</a> </li>
				'. $dropMenuList .'
				<li class="divider"></li>
				<li><a href="javascript:void(0);" onclick="UserExit();return false;"><i class="otcms-uc-exit2"></i> 退出登录</a> </li>
			</ul>
		</li>
	</ul>
	';


// 功能模块
$funcMenuStr = ''.
	AppForm::Show( SubMenu('form', '表单管理') ) .
	AppBuyOrders::Show( SubMenu('buyOrders', '订单记录') ) .
	AppCa::Show( SubMenu('ca', '广告管理') ) .
	AppAuthSoft::Show( SubMenu('authSoft', '授权软件管理') ) .
	AppTaokeOrder::Show( SubMenu('goodsOrder', '淘宝商品认领') ) .
	AppWorkCenter::Show( SubMenu('workCenter', '任务中心') . 
						SubMenu('workUsers', '任务记录') ) .
	AppGift::Show( SubMenu('giftWeb', '积分商城', '', UcBase::PcWapParDir() .'w.php?m=gift') . 
					SubMenu('gift', '积分兑换记录') ) .
	AppGetGift::Show( SubMenu('getGiftWeb', '抽奖活动', '', UcBase::PcWapParDir() .'w.php?m=getGift') . 
					SubMenu('getGift', '抽奖记录')  ) .
	AppOnePage::Show( SubMenu('onePage', '功能单页') ) .
	'';
if (strlen($funcMenuStr) > 5){
	$funcMenuStr = '
		<li class="nav-item nav-item-has-subnav '. MenuOpenClass('func') .'">
			<a href="javascript:void(0)"><i class="fa fa-puzzle-piece fa-fw"></i> 功能模块<i class="arrow"></i></a>
			<ul class="nav nav-subnav">'. $funcMenuStr .'</ul>
		</li>
		';
}


// 推广返佣
$recomMenuStr = ''.
	AppRecom::Show( SubMenu('recom', '邀请好友') ) .
	AppGain::Show( SubMenu('gainMoney', '提现记录') . 
					SubMenu('gainItem', '佣金记录') ) .
	'';
if (strlen($recomMenuStr) > 5){
	$recomMenuStr = '
		<li class="nav-item nav-item-has-subnav '. MenuOpenClass('recom') .'">
			<a href="javascript:void(0)"><i class="fa fa-share-alt fa-fw"></i> 推广返佣<i class="arrow"></i></a>
			<ul class="nav nav-subnav">'. $recomMenuStr .'</ul>
		</li>
		';
}


$moneyMenuStr = ''.
	AppXcxAd::Show( SubMenu('adGift', '广告奖励充值') ) .
	AppQuan::Show( SubMenu('quan', '卡密充值') ) .
	$moneyPayMenu .
	AppDiyPay::Show( SubMenu('diyPayRecord', '手动充值记录') ) .
	AppMoneyRecord::Show( SubMenu('moneyRecord', '财务明细') ) .
	AppUserScore::Show( SubMenu('userScore', '积分明细') ) .
	'';
if (strlen($moneyMenuStr) > 5){
	$moneyMenuStr = '
		<li class="nav-item nav-item-has-subnav '. MenuOpenClass('money') .'">
			<a href="javascript:void(0)"><i class="fa fa-dollar fa-fw"></i> 财务相关<i class="arrow"></i></a>
			<ul class="nav nav-subnav">'. $moneyMenuStr .'</ul>
		</li>
		';
}

$shimingMenu = $siteMessageMenu = '';
if ($userSysArr['US_isShiming'] > 0){
	$cardStateStr = '<span style="color:red;font-weight:bold;">进入实名认证</span>';
	switch ($userRow['UE_cardState']){
		case 1:		$cardStateStr = '<span style="color:blue;">已实名认证</span>';	break;
		case 11:	$cardStateStr = '<span style="color:blue;">已微信实名</span>';	break;
		case 21:	$cardStateStr = '<span style="color:blue;">已支付宝实名</span>';	break;
	}
	$shimingMenu = SubMenu('shiming', $cardStateStr, '', '?m=revInfo&revType=shiming');
}
if (AppSiteMessage::Jud()){
	$addiStr = '';
	$newCount = $DB->GetOne('select count(1) from '. OT_dbPref .'siteMessage where SM_userID='. $userRow['UE_ID'] .' and SM_state=0');
	$newCount += $DB->GetOne('select count(1) from '. OT_dbPref .'siteMessage where SM_userID=-1 and SM_userList not like "%['. $userRow['UE_ID'] .']%"');
	if ($newCount > 0){
		$addiStr .= '<i style="font-style:normal; display:inline-block; width:20px; height:20px; line-height:20px; margin:0 0 0 6px; text-align:center; color:#fff; font-size:14px; background:red; border-radius:6px;">'. $newCount .'</i>';
		if (in_array($userSysArr['US_siteMsgIsSound'],array(1,12)) && in_array($mudi,array('siteMessage','siteMessageAdd','siteMessageReply')) == false){
			// 开启提示音
			$addiStr .= '<embed src="inc_img/media/message3.mp3" loop="0" autostart="true" hidden="true"></embed>';
		}
	}
	$siteMessageMenu = SubMenu('siteMessage', '站内信息'. $addiStr);
}

$webMenu = '
	<script language="javascript" type="text/javascript" src="js/usersCenter.js?v='. OT_VERSION .'"></script>

	'. (strpos($userSysArr['US_userMenuList'],'|noHome|') === false ? '<li class="nav-item"> <a href="'. UcBase::PcWapParDir() .'"><i class="otcms-uc-82"></i>网站首页</a> </li>' : '') .'
	<li class="nav-item"> <a href="usersCenter.php"><i class="otcms-uc-user-1"></i>会员中心首页</a> </li>
	<li class="nav-item nav-item-has-subnav '. MenuOpenClass('def') .'">
		<a href="javascript:void(0)"><i class="fa fa-paperclip fa-fw"></i> 菜单导航</a>
		<ul class="nav nav-subnav">
		'. $shimingMenu .'
		'. (strpos($userSysArr['US_userMenuList'],'|noInfoType|') === false ? SubMenu('infoType', '<b>'. $userSysArr['US_infoTypeName'] .'</b>') : '') .'
		'. SubMenu('userAndGroup', $userSysArr['US_userAndGroupName']) .'
		'. $siteMessageMenu .'
		'. UcNews::Show( SubMenu('addNews', '发布文章') . 
						SubMenu('newsManage', '文章管理') ) .'
		'. AppUserView::Show( SubMenu('userView', '文章浏览记录') ) .'
		'. AppUserMark::Show( SubMenu('userMark', '文章收藏记录') ) .'
		'. AppInfoDown::Show( SubMenu('infoDown', '文章下载记录') ) .'
		</ul>
	</li>
	'. $funcMenuStr .'
	'. $recomMenuStr .'
	'. $moneyMenuStr .'
	<li class="nav-item nav-item-has-subnav '. MenuOpenClass('self') .'">
		<a href="javascript:void(0)"><i class="fa fa-user fa-fw"></i> 个人信息<i class="arrow"></i></a>
		<ul class="nav nav-subnav">
		'. SubMenu('revInfo', '资料密码修改') .'
		'. AppLogin::Show( SubMenu('loginApi', '快捷登录绑定') ) .'
		'. AppSiteApi::Show( SubMenu('api', 'API授权码') ) .'
		'. (strpos($userSysArr['US_userMenuList'],'|noLog|') === false ? SubMenu('log', '会员日志') : '') .'
		<li><a href="#" onclick="UserExit();return false;">退出</a></li>
		</ul>
	</li>
	';

$styleWidthStr = '';
if ($userSysArr['US_newSysWidth'] > 0){ $styleWidthStr = ' style="max-width:'. $userSysArr['US_newSysWidth'] .'px;margin:0 auto;"'; }

$tpl->Add('siteVer',		OT_VERSION);
$tpl->Add('webTypeName',	$tpl->webTypeName);
$tpl->Add('dbPathPart',		$dbPathPart);
$tpl->Add('webPathPart',	$webPathPart);
$tpl->Add('jsPathPart',		$jsPathPart);
$tpl->Add('isMobile',		UcBase::JudMobile() ? 1 : 0);
$tpl->Add('beforeURL',		UcBase::BeforeURL());

$tpl->Add('webTitle',		$tpl->webTitle);
$tpl->Add('webTop',			$webTop);
$tpl->Add('webLogo',		'<a href="usersCenter.php"><img src="static/images/uc_logo.png" /></a>');
$tpl->Add('webMenu',		$webMenu);
$tpl->Add('webContent',		$webContent);
$tpl->Add('styleWidthStr',	$styleWidthStr);

$tpl->Show('ucMain.html');


function MainArea($content, $title, $faName='snowflake-o'){
	return '
	<div class="row">
		<div class="col-lg-12">
			<div class="card">
				<div class="card-header"><h4>'. $title .'</h4></div>
		  		<div class="card-body">
		  			'. $content .'
		  		</div>
            </div>
      	</div>
    </div>';
}

function SubMenu($type, $theme, $style='', $url=''){
	global $menu2;
	if ($type == $menu2){
		$theme = '<span style="color:#0099cc;">▶</span> '. $theme .' ';
	}
	if (strlen($url) == 0){ $url = 'usersCenter.php?m='. $type; }
	$retStr = '<li><a href="'. $url .'" id="'. $type .'" style="'. $style .'">'. $theme .'</a></li>';

	return $retStr;
}

function MenuOpenClass($type){
	global $menu1;

	if ($menu1 == $type){
		return 'open';
	}
}

?>